/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
 */
Ext.ns('net.autodata.compare.impl');
(function () {
	var EVENTS = Ext.applyIf(net.autodata.EventBus.EVENTS, {
		CHANGE_COMPETITOR: 'changecompetitor',
		REMOVE_COMPETITOR: 'removecompetitor',
		LOAD_COMPETITOR: 'loadcompetitor',
		CHANGE_BASE_IMAGE: 'changebaseimage',
		CHANGE_COMPETITOR_IMAGE: 'changecompetitorimage',
		
		SESSION_COMPETITOR_CHANGED: 'session.competitorchanged',
		SESSION_COMPETITOR_REMOVED: 'session.competitorremoved',
		SESSION_VEHICLE_IMAGE_CHANGED: 'session.vehicleimagechanged'
	});
	
	/**
	 * An extension to the net.autodata.impl.EventBusImpl
	 * Accessible via the net.autodata.EventBus.getInstance method
	 * @class EventBusImpl
	 * @namespace net.autodata.impl
	 */
	var EventBusImpl = Ext.extend(net.autodata.impl.EventBusImpl, {
	
		/**
		 * @event competitorchanged
		 * Fires when a competitor vehicle is replaced with a new competitor
		 * @param {int} index The index of the competitor vehicle (1-3)
		 * @param {CompetitorVehicle} vehicle The new competitor vehicle
		 * @param {CompetitorVehicle} prevVehicle The competitor vehicle being replaced
		 */
		 
		 /**
		 * @event competitorremoved
		 * Fires when a competitor vehicle is replaced with a new competitor
		 * @param {int} index The index of the competitor vehicle (1-3)
		 * @param {CompetitorVehicle} vehicle The competitor vehicle removed
		 */
		
		/**
		 * @event loadcompetitor
		 * Fired when a new competitor record has been successfully retreived from the 
		 * CompetitorVehicleDataStore
		 * @param {int} index The index of the competitor vehicle (1-3)
		 * @param {CompetitorVehicle} vehicle The competitor vehicle
		 */

	    /**
	    * @event session.competitorchanged
	    * Fired when a competitor vehicle is changed in the CompareVehicles object stored in the 
	    * client side session object (net.autodata.Session)
	    */

	    /**
	    * @event session.competitorremoved
	    * Fired when a competitor vehicle is removed from the CompareVehicles object stored in the
	    * client side session object (net.autodata.Session)
	    */
		
		//IMPORTANT you must declare a constructore and return the result from the superclass
		//otherwise the EventBus will not initialize properly
		constructor: function ()
		{
			return EventBusImpl.superclass.constructor.apply(this, arguments);
		},
		
		/**
		 * Returns a list of events to be added to the net.autodata.EventBus
		 * @method getEvents
		 * @returns Array
		 */
		getEvents: function ()
		{
			ASC.log('net.autodata.compare.EventBus->getEvents');
			
			var eventsToAdd = {};
			eventsToAdd[EVENTS.CHANGE_COMPETITOR] = true;
			eventsToAdd[EVENTS.REMOVE_COMPETITOR] = true;
			eventsToAdd[EVENTS.LOAD_COMPETITOR] = true;

			eventsToAdd[EVENTS.SESSION_COMPETITOR_CHANGED] = true;
			eventsToAdd[EVENTS.SESSION_COMPETITOR_REMOVED] = true;
			
			var baseEvents = EventBusImpl.superclass.getEvents.apply(this, arguments) || {};
			return Ext.applyIf(baseEvents, eventsToAdd);
		}
		
	});
	net.autodata.compare.impl.EventBusImpl = EventBusImpl;	
	
	//override the getInstance method to return the extended EventBus
	/**
	 * Singleton instance to retrieve an instance of net.autodata.impl.EventBusImpl
	 * @class EventBus
	 * @singleton
	 * @namespace net.autodata
	 */
	Ext.apply(net.autodata.EventBus, {
		/**
		 * @method getInstance
		 * @returns net.autodata.impl.EventBusImpl
		 */
		getInstance: function ()
		{
			var instance = undefined;
			return function () {
				if (!instance) {
					instance = new EventBusImpl();
				}
				
				return instance;
			};
		}()
	});
})();